from django import forms
from django.utils.timezone import now
from django.forms import ModelForm
from fruits.models import goods


class ModelForm1(ModelForm):
    class Meta:
        model = goods
        fields = ['name', 'number', 'price']
        labels = {'name': 'fruit name', 'number': '数量', 'price': '单价'}
        widgets = {'name': forms.widgets.Textarea(attrs={'cols': 80, 'rows': 20})}
        error_messages = {
            'name': {'required': 'fruit name is required'},
            'number': {'required': 'fruit number is required'},
            'price': {'required': 'fruit price is required'}
        }


class FirstForm(forms.Form):
    name = forms.CharField(label='Myname', max_length=20)


class ShowFormField(forms.Form):
    fruits = forms.CharField(label='fruit name', max_length=20, min_length=2)
    number = forms.FloatField(label='sales number',min_value=0, max_value=10000, initial=1)
    price = forms.DecimalField(label='sales price', max_value=10000, min_value=0, initial=0, decimal_places=2)
    SaleDate = forms.DateField(label='sales date', input_formats='%Y 年 %m 月 %d 日', disabled=True, initial=now)


